<template>
  <div class="content">
    <div class="background">
      <div class="kong"></div>
      <img
        class="banner"
        src="https://akk.028wkf.cn/kdb-weapp-img/new-kdb-xcx/img/stock-shop-banner.png"
        mode="scaleToFill"
      />
      <div class="card">
        <div v-for="(item,index) in cardList" :key="index">
          <span>{{item.label}}</span>
          <p>{{form[item.key]}}</p>
        </div>
      </div>
      <div class="link">
        <div
          v-for="(item,index) in linkList"
          :key="index"
          @click="linkClick(item.key)"
        >
          <img :src="item.img" mode="scaleToFill" />
          <span>{{item.label}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { FIND_COUNT_MY_REBATE_AMOUNT, FIND_COUNT_MY_FROZEN_AMOUNT } from '@/api'
import { currencyFormatter } from '@/utils'

export default {
  components: {},
  props: {},
  data () {
    return {
      form: {
        rebateAmount: '0.00',
        frozenAmount: '0.00'
      },
      cardList: [
        {
          label: '我的佣金(元)',
          key: 'rebateAmount'
        },
        {
          label: '赊货锁额(元)',
          key: 'frozenAmount'
        }
      ],
      linkList: [
        {
          label: '我的商品',
          key: 'my-shop',
          img:
            'https://akk.028wkf.cn/kdb-weapp-img/new-kdb-xcx/img/stock-shop-my.png'
        },
        {
          label: '商品审核',
          key: 'my-check',
          img:
            'https://akk.028wkf.cn/kdb-weapp-img/new-kdb-xcx/img/stock-shop-check.png'
        },
        {
          label: '进货订单',
          key: 'stock-order',
          img:
            'https://akk.028wkf.cn/kdb-weapp-img/new-kdb-xcx/img/stock-shop-order.png'
        }
      ]
    }
  },
  computed: {
    account () {
      return this.$cookie.get('account')
    }
  },
  watch: {},
  created () {},
  mounted () {},
  onShow () {
    this.form = {
      rebateAmount: '0.00',
      frozenAmount: '0.00'
    }
    this.findCountMyRebateAmount()
    this.findCountMyFrozenAmount()
  },
  methods: {
    linkClick (key) {
      const vm = this
      if (key === 'my-shop') {
        vm.$router.push(
          '/pages/data-analyze/stock/supply/order/list/main?type=shop'
        )
      } else if (key === 'my-check') {
        vm.$router.push(
          '/pages/data-analyze/stock/supply/order/list/main?type=check'
        )
      } else {
        vm.$router.push(
          '/pages/data-analyze/stock/supply/order/list/main?type=stock'
        )
      }
    },
    /** api **/
    findCountMyRebateAmount () {
      const vm = this
      FIND_COUNT_MY_REBATE_AMOUNT(vm.account.shopId)
        .then(r => {
          if (r.data.code === '0') {
            vm.form.rebateAmount = currencyFormatter(r.data.data, 1, '')
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    },
    findCountMyFrozenAmount () {
      const vm = this
      FIND_COUNT_MY_FROZEN_AMOUNT(vm.account.shopId)
        .then(r => {
          if (r.data.code === '0') {
            vm.form.frozenAmount = currencyFormatter(r.data.data, 0.01, '')
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    }
  }
}
</script>

<style lang="scss" scoped>
@import 'static/styles/color.scss';
.content {
  background: #f6f8f9;
  > .background {
    background: #fff;
    position: relative;
    > .kong {
      height: 15px;
    }
    > .banner {
      width: 90%;
      height: 135px;
      position: absolute;
      left: 0;
      right: 0;
      margin: auto;
      top: 15px;
      z-index: -1;
      background: linear-gradient(to right, $new-yellow-dark, $new-yellow-tint);
    }
    .card {
      width: 90%;
      height: 135px;
      margin: auto;
      border-radius: 6px;
      background: linear-gradient(to right, $new-yellow-dark, $new-yellow-tint);
      display: flex;
      > div {
        width: 50%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        color: #fff;
        p {
          line-height: 45px;
          font-weight: 600;
        }
      }
    }
    .link {
      display: flex;
      margin-top: 20px;
      > div {
        width: 33.33%;
        height: 100px;
        display: flex;
        justify-content: center;
        flex-direction: column;
        align-items: center;
        font-size: 14px;
        color: #000;
        img {
          width: 40px;
          height: 40px;
          border-radius: 50px;
        }
        span {
          line-height: 40px;
        }
      }
    }
  }
}
</style>
